package com.baor.service.impl;

import com.baor.dao.CouponUserDao;
import com.baor.domain.CouponUserVo;
import com.baor.domain.CouponVo;
import com.baor.service.CouponService;
import com.baor.service.CouponUserService;
import com.baor.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CouponUserServiceImpl implements CouponUserService {
    @Autowired
    private CouponUserDao couponUserDao;
    @Override
    public AjaxResult<?> list(Map<String, Object> params) {
        if(params.containsKey("pageIndex")&&params.containsKey("pageSize")){
            int pageIndex= (int) params.get("pageIndex");
            int pageSize = (int) params.get("pageSize");
            params.put("pageIndex",(pageIndex - 1) * pageSize);
            List<CouponUserVo> list = this.couponUserDao.list(params);
            Map<String,Object> res = this.couponUserDao.findPageCount(params);
            res.put("list",list);
            return AjaxResult.success(res);
        }else{
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult<?> orderList(Map<String, Object> params) {
        return AjaxResult.success(this.couponUserDao.orderList(params));
    }
}
